<template>
    <div>
        <!--查询条件start --111s-->
        <el-card>
        <el-form :inline="true" :model="query" class="query-form" size="small">
         <el-form-item >
                <span >上架状态：</span>
                <el-select v-model="query.onshelfstatus" placeholder="请选择上架状态" @change="onSubmit" clearable>
                    <!-- <el-option  label="全部"  value=''>  </el-option> -->
                    <el-option  label="下架"  value='0'> </el-option>
                    <el-option label="上架" value='1'> </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <!-- <span >时间查询：</span> -->
                <el-date-picker
                    v-model="createTime"
                    unlink-panels
                    type="datetimerange"
                    :picker-options="pickerOptions"
                    range-separator="-"
                    start-placeholder="请选择开始日期"
                    end-placeholder="请选择结束日期"
                    align="left"
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    :default-time="['00:00:00','23:59:59']"
                    @change="dateChange"
                ></el-date-picker>
            </el-form-item>
            <el-button type="success" style="position:absolute;right:30px;" size="mini" @click="setMoney">代理商品起购金额设置</el-button>
        </el-form>
        <el-form :inline="true" :model="query" class="query-form" size="small">
                <el-form-item >
                    <span >分类查询：</span>
                    <el-select v-model="query.topcategoryid" placeholder="请选择一级分类" @change="topchange()" clearable>
                        <el-option
                            v-for="(item,index) in category"
                            :key="index"
                            :label="item.topcategoryname"
                            :value="item.topcategoryid">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item >
                    <el-select v-model="query.secondarycategoryid" placeholder="请选择二级分类" clearable @change="secondchange()">
                        <el-option
                            v-for="(item,index) in secondaryCategoryList"
                            :key="index"
                            :label="item.topcategoryname"
                            :value="item.topcategoryid">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item >
                    <el-select v-model="query.thirdcategoryid" placeholder="请选择三级分类" @change="onSubmit()" clearable>
                        <el-option
                            v-for="(item,index) in thirdCategoryList"
                            :key="index"
                            :label="item.topcategoryname"
                            :value="item.topcategoryid">
                        </el-option>
                    </el-select>
                </el-form-item>

        </el-form>
        <el-form :inline="true" :model="query" class="query-form" size="small">

            <el-form-item >
                <span>商品查询：</span>
            <el-form-item class="query-form-item" >
                <el-input
                    v-model="query.content"
                    placeholder="请输入商品名称"
                    prefix-icon="el-icon-search"
                    @keyup.enter.native="onSubmit"
                    clearable
                ></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" icon="el-icon-refresh" @click="onRest"></el-button>
                <el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-edit" @click.native="handleForm()">添加</el-button>
            </el-form-item>
            </el-form-item>
        </el-form>
        <!--列表start --222s-->
        <el-table
            ref="multipleTable"
            v-loading="loading"
            :data="list"
            :header-cell-style="{background:'#F4F4F5',color:'#606266'}"
            @selection-change="handleSelectionChange"
            border>
            <el-table-column type="selection" width="50" align="center" fixed/>
            <el-table-column label="商品ID" prop="commodityid" width="80" align="center"/>
            <el-table-column label="商品图片" prop="commodityicon" align="center" width="150">
                <template slot-scope="scope">
                    <el-popover v-if="scope.row.commodityicon" placement="right" trigger="hover">
                        <img :src="scope.row.commodityicon" style="width:400px;border-radius:3px;">
                        <img slot="reference" :src="scope.row.commodityicon" style="max-height: 80px;max-width: 50px;border-radius:5px;">
                    </el-popover>
                    <span v-else>-</span>
                </template>
            </el-table-column>
            <el-table-column label="商品名称" prop="commodityname" width="150" align="center"/>
            <el-table-column label="平台/品牌名称" prop="companyName" width="150" align="center">
              <template slot-scope="scope">
                    <span v-if="scope.row.belongtype ==0"> 平台</span>
                    <span v-else>金天国际（品牌）</span>
                </template>
            </el-table-column>
            <el-table-column label="一级分类" prop="topcategoryname" width="100" align="center"/>
            <el-table-column label="二级分类" prop="secondarycategoryname" width="100" align="center"/>
            <el-table-column label="三级分类" prop="thirdcategoryname" width="150" align="center"/>
            <el-table-column label="库存" prop="commoditynum" width="100" align="center"/>
            <el-table-column label="审核状态" width="120" align="center">
                <template slot-scope="scope">
                    <el-tag v-if="scope.row.commoditystatus == 0">审核中</el-tag>
                    <el-tag v-if="scope.row.commoditystatus == 1">审核通过</el-tag>
                    <el-tag v-if="scope.row.commoditystatus == 2">审核拒绝</el-tag>
                    <div v-if="scope.row.commoditystatus == 2">
                        <el-button type="text" @click="openRejectDialog(scope.row)">查看</el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="上架" prop="onshelfstatus" align="center" width="120">
                <template slot-scope="scope">
                    <el-switch
                        :disabled="scope.row.commoditystatus !==1? true:false  "
                        class="switch"
                        v-model="scope.row.onshelfstatus"
                        active-color="#13ce66"
                        inactive-color="#ff4949"
                        active-text="上架"
                        inactive-text="下架"
                        :active-value='1'
                        :inactive-value='0'
                        @change="onshelfschange(scope.row)"
                        style="margin-left: 6px;"
                    >
                    </el-switch>
                </template>
            </el-table-column>
            <el-table-column label="推荐" prop="recommendstatus" align="center" width="90">
                <template slot-scope="scope">
                    <!-- <span>{{ scope.row.recommendstatus=='1'? '推荐':'不推荐'}}</span> -->
                    <el-switch
                        class="switch"
                        v-model="scope.row.recommendstatus"
                        active-color="#13ce66"
                        inactive-color="#ff4949"
                        active-text="推荐"
                        inactive-text="不推荐"
                        :active-value='1'
                        :inactive-value='0'
                        @change="recommendchange(scope.row)"
                        style="margin-left: 6px;"
                    >
                    </el-switch>
                </template>

            </el-table-column>

            <el-table-column label="添加时间" width="180"  :show-overflow-tooltip="true" align="center">
                <template slot-scope="scope">
                    <i class="el-icon-time" v-if="scope.row.createtime!=null"></i>
                    <span
                        v-if="scope.row.createtime!=null"
                    >{{ scope.row.createtime | formatDateStr('yyyy-MM-dd hh:mm:ss') }}</span>
                </template>
            </el-table-column>

            <el-table-column label="操作" width="300"  fixed="right" align="center" >
                <template slot-scope="scope">
                    <el-button  type="primary"  size="mini"  @click.native="detailForm(scope.$index, scope.row)"  >查看 </el-button>
                    <el-button v-if="scope.row.belongtype==0" type="primary"  size="mini"  @click.native="editForm(scope.$index, scope.row)">编辑</el-button>
                    <el-button type="primary" size="mini" @click.native="inventoryForm(scope.$index, scope.row)" >库存</el-button>
                    <el-button  type="danger" size="mini"  @click.native="handleDel(scope.row.commodityid)" >删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!--列表end --222e-->
        <div class="left-container">
            <el-button type="danger" size="small" @click="delGroup()">删除已选</el-button>
            <transition name="el-fade-in-linear">
                <el-button size="small" @click="toggleSelection()" v-show="cancelToggle">取消选择</el-button>
            </transition>
        </div>
        <!--分页模块start-->
        <el-pagination
            class="pagination-container"
            background
            :page-size="query.pageSize"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            layout="total,sizes,prev, pager, next, jumper"
            :current-page="query.currentPage"
            :page-sizes="[5,10, 20, 30, 50]"
            :total="totalNumber"
        ></el-pagination>
        <!--分页模块end-->

        <!-- 代理商品起购金额设置 -->
        <el-dialog
        title="代理商品起购金额设置"
        :visible.sync="moneyVisible"
        :before-close="hidemoney"
        width="30%"
        top="5vh"
        :close-on-click-modal="false"
        >
        <template slot="title">
            <div class="avue-crud__dialog__header">
                <span class="el-dialog__title">
                <span style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
                    代理商品起购金额设置
                </span>
            </div>
        </template>
           <el-card>
           <el-form :model="funds"  size="small" :rules="rules" ref="fundsForm" :hide-requied-aterisk="true">
				<el-form-item  class="query-form-item" prop="buyfromquota" :inline="true" label="代理起购金额设置" >
					<!-- <span slot="label">代理起购金额设置</span> -->
					<el-input v-model="funds.buyfromquota" placeholder="请输入金额" @keyup.enter.native="moneySubmit('fundsForm')" clearable :maxlength="13" 
							  auto-complete="off" >
						<i slot="prefix" style="font-style: normal;font-size: 16px;">￥</i>
					</el-input>
				</el-form-item>

			</el-form>
            </el-card>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="hidemoney('fundsForm')">取消</el-button>
                <el-button type="primary" @click.native="moneySubmit('fundsForm')"  >提交</el-button>
            </div>
        </el-dialog>
        <!--查看弹框-->
        <el-dialog
            title="详情"
            :visible.sync="detailVisible"
            :before-close="hideDetailForm"
            width="50%"
            top="5vh"
            v-dialogDrag
            :close-on-click-modal="false"
        >
        <template slot="title">
        <div class="avue-crud__dialog__header">
            <span class="el-dialog__title">
            <span style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
              查看详情
            </span>
          <div class="avue-crud__dialog__menu" >
            <!-- <i class="el-icon-full-quanping"></i> -->
            <icon-svg icon-class="quanping" />
            <span  class="mention">双击全屏</span>
          </div>
        </div>
      </template>
        <el-card>
         <el-form :model="formData" label-width="140px">
                <el-form-item label-width="80px" label="基本参数" style="background: #e1e1e1" />
                <el-form-item label="商品名称：">
                    <span>{{formData.commodityname}} </span>
                    <!-- <input v-model="formData.commodityname" type="text" readonly> -->
                </el-form-item>
                <el-form-item label="商品分类：">
                    <span>{{formData.topcategoryname+","+formData.secondarycategoryname+","+formData.thirdcategoryname}}</span>
                </el-form-item>

                <el-form-item style="border-bottom:1px solid #ebeef5;" label-width="0px">

                    <el-form-item label="代理价：" style="width:30%;display: inline-block;">
                        <input v-model="formData.commodityoldprice" type="text" readonly>
                    </el-form-item>
                    <el-form-item label="零售价：" style="margin-left:80px; width:30%;display: inline-block;">
                        <input v-model="formData.commodityprice" type="text"  readonly>
                    </el-form-item>

                </el-form-item>

                <el-form-item style="border-bottom:1px solid #ebeef5;" label-width="0px">
                    <el-form-item label="添加时间：" style="width:30%;display: inline-block;">
                        <input
                            :value="formData.createtime |formatDateStr('yyyy-MM-dd') "
                            type="text"
                            readonly
                        >
                    </el-form-item>
                    <el-form-item label="商品ID：" style="margin-left:80px; width:30%;display: inline-block;">
                        <input v-model="formData.commodityid" type="text" readonly>
                    </el-form-item>

                </el-form-item>

                <el-form-item style="border-bottom:1px solid #ebeef5;" label-width="0px">

                    <el-form-item label="商品评论：" style="width:30%;display: inline-block;">
                        <el-button @click="lookcomment(formData.commodityid)" type="info" round style="margin-bottom:10px">查看</el-button>
                    </el-form-item>
                    <el-form-item label="上架：" style="margin-left:80px; width:30%;display: inline-block;" >
                        <div>
                            <el-switch
                                disabled
                                class="switch"
                                v-model="formData.onshelfstatus"
                                active-text="上架"
                                inactive-text="下架"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                                :active-value='1'
                                :inactive-value='0'
                                @change="onshelfschange(formData)"
                            >
                            </el-switch>
                        </div>
                    </el-form-item>
                </el-form-item>

                <el-form-item style="border-bottom:1px solid #ebeef5;" label-width="0px">
                    <el-form-item label="封面图：" style="width:30%;display: inline-block">
                        <!--<img :src="formData.userpic" alt style="width: 60px;height: 50px">-->
                        <el-popover v-if="formData.commodityicon" placement="right" trigger="hover">
                            <img :src="formData.commodityicon" style="width:400px;border-radius:3px;">
                            <img
                                slot="reference"
                                :src="formData.commodityicon"
                                style="max-height: 80px;max-width: 50px;border-radius:5px;"
                            >
                        </el-popover>
                        <span v-else>-</span>

                    </el-form-item>

                    <el-form-item label="库存：" style="margin-left:80px; width:30%;display: inline-block;">
                        <input v-model="formData.commoditynum" type="text" readonly>
                    </el-form-item>
                </el-form-item>

                 <!-- 商品属性-->
                <el-form-item label-width="80px" label="商品属性" style="background: #e1e1e1" />
               
                <span v-if="attributecontenct !=[] && attributecontenct !=null">
                <h3 style="height: 50px; margin-left: 40px" class="thrTitle" >基本属性</h3>
                <div :prop="'fieldname' + index" v-for="(item, index) in attributecontenct" :key="item.id">
                    <el-form-item label-width="180px" :label="item.fieldname + '：'" :prop="item.fieldname">
                    <el-input
                        v-model.trim="formData1[item.fieldname]"
                        v-if="item.fieldtype == '文字'"
                        type="text"
                        :disabled="true"
                        maxlength="10"
                        :placeholder="'请填写' + item.fieldname"
                    ></el-input>
                    <el-input
                        v-model.trim="formData1[item.fieldname]"
                        v-if="item.fieldtype == '数字'"
                        :disabled="true"
                        type="number"
                        maxlength="10"
                        :placeholder="'请填写' + item.fieldname"
                    ></el-input>

                    </el-form-item>
                </div>
                </span>

                <span v-if="attributeextendcontenct !=[] && attributeextendcontenct !=null">
                <h3 style="height: 50px; margin-left: 40px" class="thrTitle"  >扩展属性</h3>
                <div
                    :prop="'extendfieldname' + index"
                    v-for="(item, index) in attributeextendcontenct"
                    :key="item.id"
                >
                    <el-form-item
                    label-width="180px"
                    :label="item.extendfieldname + '：'"
                    >
                    <el-input
                        v-model.trim="formData1[item.extendfieldname]"

                        v-if="item.fieldtype == '文字'"
                        :disabled="true"
                        type="text"
                        maxlength="10"
                        :placeholder="'请填写' + item.extendfieldname"
                    ></el-input>
                    <el-input
                        v-model.trim="formData1[item.extendfieldname]"

                        v-if="item.fieldtype == '数字'"
                        :disabled="true"
                        type="number"
                        maxlength="10"
                        :placeholder="'请填写' + item.extendfieldname"
                    ></el-input>

                    </el-form-item>
                </div>
                </span>
                
                <!-- 商品资质认证 -->
                <el-form-item label-width="120px" label="商品资质认证" style="background: #e1e1e1"></el-form-item>
                
                <span v-if="categoryTemplate != [] && categoryTemplate != null">
                    <h3 class="thridTitle" style="height:50px">{{categoryTemplate.name || ""}}</h3>
                    <el-form-item :label="item.fieldname+'：'" :prop="'fieldname'+index" v-for="(item,index) in categoryTemplate.templateItemFormList" :key="item.id">
                        <input type="hidden" v-model="item.fieldvalue">
                        <el-input v-model="formData4[item.fieldname]" @input="onInput()" @change="changeInput(item)" v-if="item.fieldtype == '文字'" type="text" :placeholder="'请填写'+item.fieldname" disabled></el-input>
                        <el-input v-model="formData4[item.fieldname]" @input="onInput()" @change="changeInput(item)" v-if="item.fieldtype == '数字'" type="number" :placeholder="'请填写'+item.fieldname" disabled></el-input>
                        <el-popover v-if="item.fieldtype == '图片'" placement="right" trigger="hover">
                            <img :src="item.fieldvalue" style="width:400px;border-radius:3px;">
                            <img slot="reference" :src="item.fieldvalue" style="max-height: 80px;max-width: 150px;border-radius:5px;">
                        </el-popover>
                    </el-form-item>

                </span>
               
                <!--商品规格-->
                <el-table
                    ref="multipleTable"
                    v-loading="loading"
                    :data="parameterlist"
                    :header-cell-style="{background:'#F4F4F5',color:'#606266'}"
                    @selection-change="handleSelectionChange"
                    border
                >
                    <el-table-column label="商品图片" width="100"  align="center">
                        <template slot-scope="scope">
                            <el-popover v-if="scope.row.inventorypic" placement="right" trigger="hover">
                                <img :src="scope.row.inventorypic" style="width:400px;border-radius:3px;">
                                <img slot="reference" :src="scope.row.inventorypic" style="max-height: 80px;max-width: 50px;border-radius:5px;">
                            </el-popover>
                            <span v-else>-</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="规格参数" align="center">
                        <el-table-column v-for="(item,index) in inputData" :key="index" :label='item.key' width="150" align="center">
                            <template slot-scope="scope">
                                <div v-if="scope.row.splist!==undefined">
                                    <el-select v-model="scope.row.splist[index]" placeholder="请选择" disabled  ref="sel" >
                                        <el-option
                                            v-for="(it,ind) in (item.val.split(','))"
                                            :key="ind"
                                            :label="it"
                                            :value="it">
                                        </el-option>
                                    </el-select>
                                </div>
                            </template>
                        </el-table-column>
                    </el-table-column>
                    <el-table-column label="成本价" prop="costprice"  align="center"/>
                    <el-table-column label="代理价" prop="primaryagentprice"  align="center"/>
                    <el-table-column label="经销价" prop="secondaryagentprice"  align="center"/>
                    <el-table-column label="分销价" prop="commodityprice"  align="center"/>
                    <el-table-column label="零售价" prop="commodityoldprice" align="center"/>
                    <el-table-column label="县域收益占比(%)" prop="profitproportion" width="150" align="center">
                            <template slot-scope="scope">
                                <el-input-number style="width: 120px;" v-model="scope.row.profitproportion" align="center" disabled
                                :min="0" :controls="false" :precision="4" ></el-input-number>

                            </template>
                        </el-table-column>
                    <el-table-column label="库存" prop="inventorynum"  align="center"/>
                </el-table>

                <el-form-item label-width="65px" label="轮播图" style="background: #e1e1e1;margin-top:20px"/>
                <el-form-item >
                    <div v-for="(item,index) in formData.commoditypiclist" :key="index" style="display:inline-block;">
                        <img :src="item" style="width:200px;border-radius:3px;margin-left: 5px;">
                    </div>
                </el-form-item>
                <el-form-item label-width="80px" label="商品详情" style="background: #e1e1e1;margin-top:20px"/>

                    <span v-html="formData.commoditydesc" style="margin-left:10%;display:block;"></span>



            </el-form>
            </el-card>
        </el-dialog>
        <!--分类弹框-->


        <!--add新建编辑-->
        <el-dialog
            :title="formMap[formName]"
            :visible.sync="formVisible"
            :before-close="hideForm"
            width="50%"
            top="5vh"
            v-dialogDrag
            :close-on-click-modal="false"
        >
         <template slot="title">
        <div class="avue-crud__dialog__header">
            <span class="el-dialog__title">
            <span style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
             {{formMap[formName]}}
            </span>
          <div class="avue-crud__dialog__menu" >
            <!-- <i class="el-icon-full-quanping"></i> -->
            <icon-svg icon-class="quanping" />
            <span  class="mention">双击全屏</span>
          </div>
        </div>
      </template>
      <el-card>
            <el-form :model="formData" :rules="formRules" ref="ruleForm">
                <el-form-item label-width="80px" label="基本参数" style="background: #e1e1e1">
                </el-form-item>
                <el-form-item label-width="120px" label="商品名称：" prop="commodityname">
                    <!-- 新增上架、下架start -->
                    <div style="float:right;margin-right: 20px;">
                        <el-radio v-model="radio" label="1">上架</el-radio>
                        <el-radio v-model="radio" label="2">下架</el-radio>
                    </div>
                    <!-- 新增上架、下架end -->
                    <el-input style="width: 60%" v-model="formData.commodityname" placeholder="请输入商品名称" clearable></el-input>
                </el-form-item>

                <el-form-item label-width="120px" label="商品分类："  required>
                    <div style="width: 100%">
                        <!-- <div v-if="ThirdCategoryobj.thirdcategoryname!==undefined">
                            <span>{{categoryobj.topcategoryname+","+SecondaryCategoryobj.secondarycategoryname+","+ThirdCategoryobj.thirdcategoryname}}</span>
                        </div> -->
                        <!-- <el-button type="primary" @click="chosebtn()" style="margin-left: 50px;">选择111111111分类</el-button> -->

                            <el-col :span="6">
                                <el-form-item prop="topcategoryid">
                                <el-select v-model="formData.topcategoryid" clearable placeholder="请选择一级分类" @change="topchange1()" >
                                    <el-option
                                        v-for="(item,index) in category"
                                        :key="index"
                                        :label="item.topcategoryname"
                                        :value="item.topcategoryid">
                                    </el-option>
                                </el-select>
                                </el-form-item>
                            </el-col>

                            <el-col :span="6">
                                <el-form-item prop="secondarycategoryid">
                                    <el-select v-model="formData.secondarycategoryid" clearable placeholder="请选择二级分类"
                                            @change="secondchange1()">
                                        <el-option
                                            v-for="(item,index) in secondaryCategoryList"
                                            :key="index"
                                            :label="item.topcategoryname"
                                            :value="item.topcategoryid">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item prop="thirdcategoryid">
                                    <el-select v-model="formData.thirdcategoryid" placeholder="请选择三级分类" clearable @change="thirdchange1()">
                                        <el-option v-for="(item,index) in thirdCategoryList"
                                                :key="index"
                                                :label="item.topcategoryname"
                                                :value="item.topcategoryid">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>


                    </div>
                </el-form-item>

                <!-- 新增商品类型start -->
                <!-- <el-form-item label-width="120px"  label="商品类型：" prop="commodityname">
                    <el-select v-model="formData.commoditytype" placeholder="请选择"  clearable>
                        <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item> -->

                 <!-- 商品属性-->
            <el-form-item
              label-width="80px"
              label="商品属性"
              style="background: #e1e1e1"
              v-show="categoryTemplateShow" />
              <el-form :model="formData1" :rules="form1Rules" ref="formData1">
              <span v-if=" attributecontenct !=null && attributecontenct !=[]">
              <h3 style="height: 50px; margin-left: 40px" class="thrTitle" v-show="categoryTemplateShow">基本属性</h3>
              <div
                v-for="item in formData.attributecontenct"
                :key="item.id"
              >
                <el-form-item  label-width="180px"   :label="item.fieldname + '：'" :prop="item.fieldname" >
                  <el-input
                    v-model.trim="formData1[item.fieldname]"
                    @input="onInput1()"
                    @change="changeInput1(item)"
                    v-if="item.fieldtype == '文字'"
                    type="text"
                    maxlength="10"
                    :placeholder="'请填写' + item.fieldname"
                  ></el-input>
                  <el-input
                    v-model.trim="formData1[item.fieldname]"
                    @change="changeInput1(item)"
                    v-if="item.fieldtype == '数字'"
                    oninput="value=value.replace(/[^\d]/g,'').slice(0,10)"
                    type="number"
                    :min="0"
                    :placeholder="'请填写' + item.fieldname+'（数字类型）'"
                  ></el-input>

                </el-form-item>
              </div>
            </span>

            <span v-if="attributeextendcontenct !=[] && attributeextendcontenct !=null">
              <h3 style="height: 50px; margin-left: 40px" class="thrTitle" v-show="categoryTemplateShow">扩展属性</h3>
              <div
                :prop="'extendfieldname' + index"
                v-for="(item, index) in attributeextendcontenct"
                :key="item.id"
              >
                <el-form-item
                  label-width="180px"
                  :label="item.extendfieldname + '：'"
                  :prop="item.extendfieldname"
                >
                  <el-input
                    v-model.trim="formData1[item.extendfieldname]"
                    @input="onInput2()"
                    @change="changeInput2(item)"
                    v-if="item.fieldtype == '文字'"
                    type="text"
                    maxlength="10"
                    :placeholder="'请填写' + item.extendfieldname"
                  ></el-input>
                  <el-input
                    v-model.trim="formData1[item.extendfieldname]"
                    oninput="value=value.replace(/[^\d]/g,'').slice(0,10)"
                    @change="changeInput2(item)"
                    v-if="item.fieldtype == '数字'"
                    :min="0"
                    type="number"
                    :placeholder="'请填写' + item.extendfieldname+'（数字类型）'"
                  ></el-input>

                </el-form-item>
              </div>
            </span>
            </el-form>
                <!--商品资质认证-->
                <el-form-item label-width="120px" label="商品资质认证" style="background: #e1e1e1">
                </el-form-item>
                <el-form :model="formData4" :rules="form4Rules" ref="formData4">
                <span v-if="categoryTemplate != [] && categoryTemplate != null">
                    <h3 style="height: 50px" class="thridTitle">{{categoryTemplate.name || ""}}</h3>
                    <div :prop="'fieldname'+index" v-for="(item,index) in categoryTemplate.templateItemFormList" :key="item.id">
                    <el-form-item label-width="180px" :label="item.fieldname+'：'" :prop="item.fieldname">
                       <input type="hidden" v-model="item.fieldvalue" />
                        <el-input v-model="formData4[item.fieldname]" @input="onInput()" @change="changeInput(item)" v-if="item.fieldtype == '文字'" type="text" :placeholder="'请填写'+item.fieldname"></el-input>
                        <el-input v-model="formData4[item.fieldname]" @input="onInput()" @change="changeInput(item)" v-if="item.fieldtype == '数字'" type="number" :placeholder="'请填写'+item.fieldname"></el-input>
                        <el-upload
                            v-if="item.fieldtype == '图片'"
                            :action="uploadUrl"
                            :on-success="(response, file,fileList)=> handleFieldSuccess(response, file,fileList,'formData4',item.fieldname,index)"
                            :on-remove="(file,fileList)=> handleFieldPicRemove(file, fileList,'formData4','fieldname' + index,index)"
                            :on-change="(file)=> handleChange(file)"
                            list-type="picture-card"
                            :show-file-list="false"
                            class="avatar-uploader"
                        >
                        <img v-if="item.fieldvalue" :src="item.fieldvalue" class="avatar" style="width: 100%; height: 100%">
                        <i v-else class="el-icon-plus"></i>
                        </el-upload>
                    </el-form-item>
                    </div>
                </span>
                </el-form>
                <!--2-->
                <el-form-item label-width="80px" label="规格参数" style="background: #e1e1e1">
                </el-form-item>
                <el-form-item>
                    <div v-for="(item,index) in inputData" :key="index">
                        <el-form-item style=" width:30%;display: inline-grid;">
                            <div style="float: none">
                                <el-tag>{{item.key}}</el-tag>
                                <el-input
                                    v-model="item.val"
                                    placeholder="请输入内容"
                                    clearable
                                    size="small"
                                />
                            </div>

                        </el-form-item>
                    </div>
                </el-form-item>
                <!--3-->
                <el-form-item label-width="55px" label="库存" style="background: #e1e1e1">
                    <span>{{formData.commoditynum}}</span>
                </el-form-item>

                <el-form-item>
                    <el-table
                        ref="multipleTable"
                        v-loading="loading"
                        :data="parameterlist"
                        :header-cell-style="{background:'#F4F4F5',color:'#606266'}"
                        @selection-change="handleSelectionChange"
                        border
                    >
                        <el-table-column label="商品图片" width="100"  align="center" fixed>
                            <template slot-scope="scope">
                                <el-upload
                                    ref="upload"
                                    class="avatar-uploader"
                                    :data="uploadData1"
                                    :action="uploadUrl"
                                    :show-file-list="false"
                                    :on-success="handleAvatarSuccess"
                                    @click.native="curRowIndex=scope.$index"
                                >
                                    <img v-if="scope.row.inventorypic" :src="scope.row.inventorypic" class="avatar"
                                         style="width: 50px;height: 50px">
                                    <i v-else class="el-icon-plus avatar-uploader-icon"
                                       style="line-height: 2.3"></i>
                                </el-upload>
                            </template>
                        </el-table-column>
                        <el-table-column label="规格参数" align="center">
                            <el-table-column v-for="(item,index) in inputData" :key="index" :label='item.key' width="150" align="center">
                                <template slot-scope="scope">
                                    <div v-if="scope.row.splist!==undefined">

                                        <el-select v-model="scope.row.splist[index]" placeholder="请选择" clearable ref="sel"
                                                   @change="paramchange($event,scope.$index,scope.row,index,item)" >
                                            <el-option
                                                v-for="(it,ind) in (item.val.split(','))"
                                                :key="ind"
                                                :label="it"
                                                :value="it">
                                            </el-option>
                                        </el-select>
                                    </div>
                                </template>
                            </el-table-column>
                        </el-table-column>

                         <el-table-column label="成本价" prop="costprice" width="150" align="center">
                            <template slot-scope="scope">
                                <el-input-number style="width: 120px;" v-model="scope.row.costprice" align="center" @change="costprice(scope.$index,scope.row)"
                                :min="0" :controls="false" :precision="2"></el-input-number>

                            </template>
                        </el-table-column>
                        <el-table-column label="代理价" prop="primaryagentprice" width="150" align="center">
                            <template slot-scope="scope">
                                <el-input-number style="width: 120px;" v-model="scope.row.primaryagentprice" align="center" @change="primaryagentpriceChange(scope.$index,scope.row)"
                                :min="0" :controls="false" :precision="2"></el-input-number>

                            </template>
                        </el-table-column>
                        <el-table-column label="经销价" prop="secondaryagentprice" width="150" align="center">
                            <template slot-scope="scope">
                                <el-input-number style="width: 120px;" v-model="scope.row.secondaryagentprice" align="center"
                                :min="0" :controls="false" :precision="2" @change="secondaryagentprice(scope.$index,scope.row)"></el-input-number>

                            </template>
                        </el-table-column>
                        <el-table-column label="分销价" prop="commodityprice" width="150" align="center">
                            <template slot-scope="scope">
                                 <el-input-number style="width: 120px;" v-model="scope.row.commodityprice" align="center"
                                :min="0" :controls="false" :precision="2" @change="commodityprice(scope.$index,scope.row)"></el-input-number>

                            </template>
                        </el-table-column>
                        <el-table-column label="零售价" prop="commodityoldprice" width="150" align="center">
                            <template slot-scope="scope">
                                <el-input-number style="width: 120px;" v-model="scope.row.commodityoldprice" align="center"
                                :min="0" :controls="false" :precision="2" @change="commodityoldprice(scope.$index,scope.row)"></el-input-number>
                            </template>
                        </el-table-column>
                        <el-table-column label="县域收益占比(%)" prop="profitproportion" width="150" align="center">
                            <template slot-scope="scope">
                                <el-input-number style="width: 120px;" v-model="scope.row.profitproportion" align="center"
                                :min="0" :controls="false" :precision="4" @change="profitproportion(scope.$index,scope.row)"></el-input-number>

                            </template>
                        </el-table-column>

                        <el-table-column label="操作" align="center" fixed="right">
                            <template slot-scope="scope">
                                <el-button
                                    type="danger"
                                    size="mini"
                                    @click.native="paraDel(scope.$index,scope.row)"
                                >删除
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div align="center" style="margin: 10px;">
                        <el-button :disabled="formData.thirdcategoryid==''" type="primary" @click="addpara()">添加</el-button>

                    </div>
                </el-form-item>
                <!--3-->
                <el-form-item label-width="65px" label="轮播图" style="background: #e1e1e1">
                </el-form-item>
                <el-form-item style="display: inline-block">

                    <div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
                    <el-upload
                        :action="uploadUrl"
                        :on-change="handleChange"
                        list-type="picture-card"
                        :on-success="handleSuccess"
                        :on-remove="handlePicRemove"
                        :file-list="uploadData"
                    ><i class="el-icon-plus"></i>
                    </el-upload>
                </el-form-item>
                <el-form-item label-width="80px" label="商品详情" style="background: #e1e1e1"></el-form-item>

            </el-form>

            <div>
                <!-- 图片上传组件辅助-->
                <el-upload
                    class="edituploader"
                    :action="uploadUrl"
                    :show-file-list="false"
                    :on-success="imguploadSuccess"
                    :on-error="uploadError"
                    :before-upload="beforeUpload">
                </el-upload>
                <quill-editor
                    v-model="formData.commoditydesc"
                    ref="myQuillEditor"
                    :options="editorOption"
                    @change="onEditorChange($event)"
                >
                </quill-editor>
            </div>
            </el-card>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="hideForm">取消</el-button>
                <el-button type="primary" @click.native="formSubmit()"  v-bind:disable="dis" :disabled="formdisabled" :loading="formLoading">提交</el-button>
            </div>
        </el-dialog>
        <!-- -->
        <!--库存管理-->
        <el-dialog
            :title="formMap[formName]"
            :visible.sync="inventoryVisible"
            :before-close="hideInventoryForm"
            width="50%"
            top="5vh"
            v-dialogDrag
            :close-on-click-modal="false"
        >
        <template slot="title">
            <div class="avue-crud__dialog__header">
                <span class="el-dialog__title">
                <span style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
                {{formMap[formName]}}
                </span>
                <div class="avue-crud__dialog__menu" >
                    <!-- <i class="el-icon-full-quanping"></i> -->
                    <icon-svg icon-class="quanping" />
                    <span  class="mention">双击全屏</span>
                </div>
            </div>
        </template>
      <el-card>
            <el-form :model="formData" label-width="140px">
                <el-form-item label-width="80px" label="商品名称" style="background: #e1e1e1"></el-form-item>
                <el-form-item label="商品名称：">
                    <span>{{formData.commodityname}} </span>
                    <!-- <input v-model="formData.commodityname" type="text" readonly> -->
                </el-form-item>
                <!--商品规格-->
                <el-form-item label-width="80px" label="商品规格" style="background: #e1e1e1"></el-form-item>
                <el-table
                    ref="multipleTable"
                    v-loading="loading"
                    :data="parameterlist"
                    :header-cell-style="{background:'#F4F4F5',color:'#606266'}"
                >
                    <!--商品规格-->
                    <el-table-column label="商品图片" width="100"  align="center">
                        <template slot-scope="scope">
                            <el-popover v-if="scope.row.inventorypic" placement="right" trigger="hover">
                                <img :src="scope.row.inventorypic" style="width:400px;border-radius:3px;">
                                <img
                                    slot="reference"
                                    :src="scope.row.inventorypic"
                                    style="max-height: 80px;max-width: 50px;border-radius:5px;"
                                >
                            </el-popover>
                            <span v-else>-</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="规格参数" align="center">
                        <div v-if="inputData.length>0">
                            <el-table-column v-for="(item,index) in inputData" :key="index" :label='item.key' width="150" align="center">
                                <template slot-scope="scope">
                                    <div v-if="scope.row.splist!==undefined">
                                        <el-select v-model="scope.row.splist[index]" placeholder="请选择" disabled  ref="sel" >
                                            <el-option
                                                v-for="(it,ind) in (item.val.split(','))"
                                                :key="ind"
                                                :label="it"
                                                :value="it">
                                            </el-option>
                                        </el-select>
                                    </div>
                                </template>
                            </el-table-column>
                        </div>
                    </el-table-column>
                    <el-table-column label="成本价" prop="costprice"  align="center"/>
                    <el-table-column label="代理价" prop="primaryagentprice"  align="center"/>
                    <el-table-column label="经销价" prop="secondaryagentprice"  align="center"/>
                    <el-table-column label="分销价" prop="commodityprice"  align="center"/>
                    <el-table-column label="零售价" prop="commodityoldprice" align="center"/>
                    <el-table-column label="库存" prop="inventorynum" width="150" align="center">
                        <template slot-scope="scope">
                            <el-input-number :min="0" :max="99999" v-model="scope.row.inventorynum" controls-position="right" placeholder="请输入商品库存" clearable >

                            </el-input-number>
                        </template>
                    </el-table-column>
                    <el-table-column label="起购数量" prop="buyfromnum" width="150" align="center">
                        <template slot-scope="scope">
                             <el-input-number v-model="scope.row.buyfromnum" controls-position="right" placeholder="起购数量" clearable :min="1" :max="99999" >

                             </el-input-number>
                        </template>
                    </el-table-column>
                </el-table>
                <el-form-item>
                    <div align="left" style="margin:30px -130px ; width:50%;overflow-y: hidden;">
                        <el-button type="primary"   @click="inventoryFormSubmit">提交</el-button>
                    </div>
                </el-form-item>
            </el-form>
        </el-card>
        </el-dialog>
        </el-card>
    </div>
</template>
<script>
    import {
        getList,
        delBusCommodity,
        addBusCommodity,
        updateBusCommodity,
        updateCommodityInventory,
        getGoodsCertificationInfo,
        upProfitBili,
        getProfitBiliInfo
    } from "../../api/buscommodity/buscommodity.js";
    import Tinymce from "../../components/Tinymce/index.vue";
    import {BASE_URL} from "../../config/app";
    import { quillEditor } from "vue-quill-editor"; //调用编辑器
    import 'quill/dist/quill.core.css';
    import 'quill/dist/quill.snow.css';
    import 'quill/dist/quill.bubble.css';
    import {getCategory} from "../../api/classification/classification.js";

    /*用作表单的数据初始化*/
    const formJson = {
        attributecontenct: "",//商品基本属性
        attributeextendcontenct: "",//扩展属性
        commodityid: "",//商品id
        commodityname: "",//商品名称
        recommendstatus: 0,//商品'0不推荐1推荐',
        onshelfstatus: 1,//商品 0全部，  1不上架 2上架',
        commodityicon: "",//商品图片
        commodityprice: "",// 分销价    decimal(20,2),
        commodityoldprice: "",//成本价    decimal(20,2),
        profitproportion:"",//县域百分比
        commodityfrom: "",// 货源地
        topcategoryname: "",//一级分类
        secondarycategoryname: "",//二级分类
        thirdcategoryname: "",//三级分类
        commoditytype:"",
        commoditynum: "",// 库存
        createtime: "",// 添加时间
        commoditydesc: "",//商品描述
        commoditypiclist: [],//图片
        piclist: "", //图片列表
        videopic:"" , //视频地址
        commoditystatus:"",//审核状态
        /**/
        topcategoryid: "",//一级分类id',
        secondarycategoryid: "",//二级分类id',
        thirdcategoryid: "",// 三级分类id,
        inids: "" ,//参数id
        param:"",
        inputdata:"",//全部参数
        certificationcontent:"",
        belongtype:"",
        companyName:""
    };
    /*富文本*/
    const toolbarOptions = [
        ['bold', 'italic', 'underline', 'strike'],    // toggled buttons
        [{'header': 1}, {'header': 2}],        // custom button values
        [{'list': 'ordered'}, {'list': 'bullet'}],
        [{'indent': '-1'}, {'indent': '+1'}],     // outdent/indent
        [{'direction': 'rtl'}],             // text direction
        [{'size': ['small', false, 'large', 'huge']}], // custom dropdown
        [{'header': [1, 2, 3, 4, 5, 6, false]}],
        [{'color': []}, {'background': []}],     // dropdown with defaults from theme
        [{'font': []}],
        [{'align': []}],
        ['link', 'image'],
        ['clean']

    ]
    export default {
        components: {
            Tinymce ,
            quillEditor
        },

        data() {
            const validateMoney = (rule,value,callback) =>{
            if(!value){
                callback(new Error('金额不能为空'))
                
            }else if(value==0){
                callback(new Error('调整金额不能为0'))
            }else if(value.split('.').length > 2){
                callback(new Error('输入正确格式的金额')) //防止输入多个小数点
            }else{
                // value = Math.round(value * Math.pow(10,2)) / Math.pow(10,2) //四舍五入
                // value = Number(value).toFixed(2); //不足补位
                function getFloatNumber(num) {
                    num += '';
                    num = num.replace(/[^0-9|\.]/g, '');
                    if (/^0+/) num = num.replace(/^0+/, '');
                    if (!/\./.test(num)) num += '.00';
                    if (/^\./.test(num)) num = '0' + num;
                    num += '00';
                    num = num.match(/\d+\.\d{2}/)[0];
                    return num;
                }
                this.funds.buyfromquota =getFloatNumber(value);
                callback();
                }
            };
            return {
                form1Rules: {},
                form4Rules: {},
                dialogFull:false,
                radio: '1',
                options: [
                    {
                        value: 0,
                        label: '代理商品'
                    },
                    {
                        value: 1,
                        label: '代理自营商品'
                    },
                ],
                pickerOptions: {//快速选择日期
                    shortcuts: [
                        {
                            text: "最近一周",
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(
                                    start.getTime() - 3600 * 1000 * 24 * 7
                                );
                                picker.$emit("pick", [start, end]);
                            }
                        },
                        {
                            text: "最近一个月",
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(
                                    start.getTime() - 3600 * 1000 * 24 * 30
                                );
                                picker.$emit("pick", [start, end]);
                            }
                        },
                        {
                            text: "最近三个月",
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(
                                    start.getTime() - 3600 * 1000 * 24 * 90
                                );
                                picker.$emit("pick", [start, end]);
                            }
                        },
                        {
                            text: "最近六个月",
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(
                                    start.getTime() - 3600 * 1000 * 24 * 180
                                );
                                picker.$emit("pick", [start, end]);
                            }
                        }
                    ]
                },
                formData1:{},//商品属性模板
                formData4: {
                    // 第四步表单
                    storename: null, // 店铺名称
                    enterinfoid: null, // 主键
                    certificationcontent: null, // 商品分类模板
                    topcategoryid: null, // 一级商品分类id
                    secondarycategoryid: null, // 二级商品分类id
                    categoryid: null // 三级商品分类id
                },
                funds:{
                    buyfromquota:'0.00',
                    id:''
                },
                rules:{
					buyfromquota: [ {validator:validateMoney,trigger:'blur' }],
                },
                moneyVisible:false,//设置金额弹窗
                formdisabled:false,
                query: {//查询条件
                    content: "",
                    starttime: "",
                    endtime: "",
                    onshelfstatus: '',//0全部，  1不上架 2上架
                    recommendstatus: "",//0不推荐1推荐
                    currentPage: 1,
                    pageSize: 5,
                    topcategoryid: "", //一级
                    secondarycategoryid: "",//二级
                    thirdcategoryid: ""//三级
                },
                formData: formJson,//新增或修改的对象
                emptyTemplate: [], //空模板
                commoditypiclist:[],
                formName: '',
                formMap: {
                    add: "添加",
                    edit: "编辑",
                    detail: "查看",
                    examine:"审核",
                    inventoryEdit: "库存"
                },
                inventoryVisible: false, //库存管理编辑显示
                uploadUrl: BASE_URL + '/goldendays-currency/tool/uploadpro',//上传图片
                uploadvideo: BASE_URL + "/tool/uploadVideo",//上传视频
                uploadData: [],//[{name:"12",url:"http://localhost/maotianxiaupload/common/2019-08-23/MH1566545692219_mid.jpg"}], // 图片data
                vuploadData:[], //视频
                uploadData1: {}, // 图片data
                curRowIndex: 0,//图片row
                createTime: [],//选择日期时需要的model
                list: [],//列表集合
                parameterlist: [], //add参数list
                category: [],//分类列表
                buswarehouse: [],//仓库列表
                secondaryCategoryList: [], //二级
                thirdCategoryList: [],//三级
                categoryobj: {},//分类列表
                SecondaryCategoryobj: {}, //二级
                ThirdCategoryobj: {},//三级
                inputData: [],// 循环创建input存值
                totalNumber: 0,//分页总页数
                formVisible: false,//添加编辑显示
                loading: true,//列表加载
                dis:true,//不可点击
                formLoading: false,//表单提交加载
                allLoding: false,//全屏加载
                cancelToggle: false,
                detailVisible: false,//查看
                categoryTemplateShow: true,
                classification: false,
                dialogFormVisible: false,
                formSumbitLoding: false, //表单提交加载
                multipleSelection: [], //多选集合
                commodityid:"",

                formRules: {
                    commodityname: {
                        required: true,
                        message: "请输入名称",
                        trigger: "blur"
                    },
                    topcategoryid:{
                        required: true,
                        message: "请选择一级分类",
                        trigger: "change"
                    },
                    secondarycategoryid:{
                        required: true,
                        message: "请选择一级分类",
                        trigger: "change"
                    },
                    thirdcategoryid:{
                        required: true,
                        message: "请选择三级分类",
                        trigger: "change"
                    },
                    // commoditytype:{
                    //     required: true,
                    //     message: "请选择类型",
                    //     trigger: "change"
                    // },
                    // distributionprice: {
                    //     required: true,
                    //     message: "请输入分销价",
                    //     trigger: "blur"
                    // },
                    // firstagentprice: {
                    //     required: true,
                    //     message: "请输入代理价",
                    //     trigger: "blur"
                    // },
                    // secagentprice: {
                    //     required: true,
                    //     message: "请输入经销价",
                    //     trigger: "blur"
                    // },
                    commoditydesc: {
                        required: true,
                        message: "请输入商品详情",
                        trigger: "blur"
                    },
                },
                attributecontenct:[],//商品属性
                attributeextendcontenct:[],//商品属性模板
                categoryTemplate: [], // 商品类目模板
                quillUpdateImg: false, // 根据图片上传状态来确定是否显示loading动画，刚开始是false,不显示
                // content: null,
                editorOption: {
                    placeholder: '',
                    theme: 'snow', // or 'bubble'
                    modules: {
                        toolbar: {
                            container: toolbarOptions,
                            handlers: {
                                'image': function (value) {
                                    if (value) {
                                        // 触发input框选择图片文件
                                        document.querySelector('.edituploader input').click()
                                    } else {
                                        this.quill.format('image', false);
                                    }
                                }
                            }
                        }
                    }
                },
            };
        },
        watch: {},
        methods: {
            costprice(index,row){
                if(row.primaryagentprice!=null&&row.primaryagentprice!=""&&row.costprice!=null&&row.costprice!=""){
                    var primaryagentprice=row.primaryagentprice-0;
                    var costprice=row.costprice-0;
                    if(primaryagentprice<costprice){
                        this.openAlert("成本价不能高于于代理价,请重新输入!");
                        row.costprice = "";
                        return false;
                    }
                }
            },
            primaryagentpriceChange(index,row){
                if(row.primaryagentprice!=null&&row.primaryagentprice!=""&&row.costprice!=null&&row.costprice!=""){
                    var primaryagentprice=row.primaryagentprice-0;
                    var costprice=row.costprice-0;
                    if(primaryagentprice<costprice){
                        this.openAlert("代理价不能低于成本价,请重新输入!");
                        row.primaryagentprice = "";
                        return false;
                    }
                }
                if(row.primaryagentprice!=null&&row.primaryagentprice!=""&&row.secondaryagentprice!=null&&row.secondaryagentprice!=""){
                    var primaryagentprice1=row.primaryagentprice-0;
                    var secondaryagentprice=row.secondaryagentprice-0;
                    if(secondaryagentprice<primaryagentprice1){
                        this.openAlert("代理价不能高于经销价,请重新输入!");
                        row.primaryagentprice = "";
                        return false;
                    }
                }
            },
            secondaryagentprice(index,row){
                if(row.primaryagentprice!=null&&row.primaryagentprice!=""&&row.secondaryagentprice!=null&&row.secondaryagentprice!=""){
                    var primaryagentprice=row.primaryagentprice-0;
                    var secondaryagentprice=row.secondaryagentprice-0;
                    if(secondaryagentprice<primaryagentprice){
                        this.openAlert("经销价不能低于代理价,请重新输入!");
                        row.secondaryagentprice = "";
                        return false;
                    }
                }
                if(row.commodityprice!=null&&row.commodityprice!=""&&row.secondaryagentprice!=null&&row.secondaryagentprice!=""){
                    var commodityprice=row.commodityprice-0;
                    var secondaryagentprice1=row.secondaryagentprice-0;
                    if(commodityprice<secondaryagentprice1){
                        this.openAlert("经销价不能高于分销价,请重新输入!");
                        row.secondaryagentprice = "";
                        return false;
                    }
                }
            },
            commodityprice(index,row){
                if(row.commodityprice!=null&&row.commodityprice!=""&&row.secondaryagentprice!=null&&row.secondaryagentprice!=""){
                    var commodityprice=row.commodityprice-0;
                    var secondaryagentprice=row.secondaryagentprice-0;
                    if(commodityprice<secondaryagentprice){
                        this.openAlert("分销价不能低于经销价,请重新输入!");
                        row.commodityprice = "";
                        return false;
                    }
                }
                if(row.commodityprice!=null&&row.commodityprice!=""&&row.commodityoldprice!=null&&row.commodityoldprice!=""){
                    var commodityprice1=row.commodityprice-0;
                    var commodityoldprice=row.commodityoldprice-0;
                    if(commodityoldprice<commodityprice1){
                        this.openAlert("分销价不能高于零售价,请重新输入!");
                        row.commodityprice = "";
                        return false;
                    }
                }
            },
            commodityoldprice(index,row){
                if(row.commodityprice!=null&&row.commodityprice!=""&&row.commodityoldprice!=null&&row.commodityoldprice!=""){
                    var commodityprice=row.commodityprice-0;
                    var commodityoldprice=row.commodityoldprice-0;
                    if(commodityoldprice<commodityprice){
                        this.openAlert("零售价不能低于分销价,请重新输入!");
                        row.commodityoldprice = "";
                        return false;
                    }
                }
            },

           profitproportion(index,row){
                if(row.profitproportion !=null&&row.profitproportion !=""){
                    if(row.profitproportion>99.9999 || row.profitproportion<0.0001){

                        this.$message.error("县域收益占比应设置1~100之间!");

                        return false
                    }

                }

            },
            openAlert(msg) {
                if(msg!=null && msg!=''){
                    this.$message({
                        message: msg,
                        type: 'error',
                        offset: 60
                    });
                }
                return false;
            },
            hideInventoryForm() {
                // 更改值
                this.inventoryVisible = !this.inventoryVisible;
                return true;
            },
            // handleInventoryInput(row) {

            //     if(row.inventorynum>99999 ||row.inventorynum.length>6){

            //        this.$message.warning("库存输入最大值不能大于99999")
            //        row.inventorynum=0;
            //        return
            //     }
            // },
            // handlebuyfromnumInput(row){

            //     if(row.buyfromnum>99999){
            //        this.$message.warning("起购量最大值不能大于99999")
            //        row.inventorynum=0;
            //        return
            //     }
            // },
            //图片上传成功
            handleFieldSuccess(response, file, fileList, index, key, item) {
                if (response.status === 1) {
                    this.$set(this[index], key, response.data);
                    if (item || item == 0) {
                        this.categoryTemplate.templateItemFormList[item].fieldvalue = this.formData4[key];
                        this.$refs["formData4"].validate((valid) => {
                            if(valid){
                                this.$refs["formData4"].clearValidate();
                            }
                        });
                    }
                    
                    return;
                }
                this.$message.error("上传文件报错");
            },
            // 移除图片
            handleFieldPicRemove(file, fileList, index, key, item) {
                this[index][key] = null;
                if (item || item == 0) {
                    this.categoryTemplate.templateItemFormList[
                        item
                        ].fieldvalue = null;
                }
            },
           
            // 强制刷新input
            onInput() {
                this.$forceUpdate();
            },
            // 模板input监听
            changeInput(val) {
                val.fieldvalue = this.formData4[val.fieldname];
                // console.log(this.formData4);
            },
            // 商品基本属性强制刷新input
            onInput1() {
                this.$forceUpdate();
            },
            // 模板input监听
            changeInput1(val) {
                val.fieldvalue = this.formData1[val.fieldname];
                console.log(val)
            },
             // 商品扩展属性强制刷新input
            onInput2() {
                this.$forceUpdate();
            },
            // 商品扩展属性模板input监听
            changeInput2(val) {
                val.fieldvalue = this.formData1[val.extendfieldname];
                console.log(val)
            },


            onEditorChange({editor, html, text}) {//内容改变事件
                // console.log("---内容改变事件---")
                this.formData.commoditydesc = html
                // console.log(html)
            },
            // 富文本图片上传前
            beforeUpload() {
                // 显示loading动画
                this.quillUpdateImg = true
            },

            imguploadSuccess(response, file) {
                // res为图片服务器返回的数据
                // 获取富文本组件实例
                // console.log(response);
                let quill = this.$refs.myQuillEditor.quill

                // 如果上传成功
                if (response.status === 1 ) {
                    let filePath = response.data;
                    // 获取光标所在位置
                    let length = quill.getSelection().index;
                    // 插入图片 res.url为服务器返回的图片地址
                    quill.insertEmbed(length, 'image', filePath)
                    // 调整光标到最后
                    quill.setSelection(length + 1)
                    this.$message.success('图片插入成功')
                } else {
                    this.$message.error('图片插入失败')
                }
                // loading动画消失
                this.quillUpdateImg = false

            },
            // 富文本图片上传失败
            uploadError() {
                // loading动画消失
                this.quillUpdateImg = false
                this.$message.error('图片插入失败')
            },


            //table列表参数
            paramchange(e,i,row,index,it){

                console.info(i+"=="+index+"---------"+this.inputData)
                let data={};
                this.$set(data,it.key,e);
                this.parameterlist[i].savparameterlist[index]=data;
                console.info(this.parameterlist[i].savparameterlist);
            },
            arrNumber(arr){
                var arr_number = {};
                for(var i = 0 ; i < arr.length ; i++){
                    if(arr_number[arr[i]]){
                        arr_number[arr[i]]++
                    }
                    else{
                        arr_number[arr[i]] = 1 ;
                    }
                }
                return arr_number ;
            },
            formSubmit() {
                let plist = this.parameterlist;
                // if(plist!=null && plist.length==0){
                //     this.$message.warning("请选择完商品基本参数，资质，规格，再点击提交")
                //     return false;
                // }
                for (let i = 0; i < plist.length; i++) {
                    let jsonval = JSON.stringify(plist[i].savparameterlist);

                    // var json = [{dd:'SB',AA:'东东',re1:123},{cccc:'dd',lk:'1qw'}];
                    let json=plist[i].savparameterlist
                    let indata={};
                    for(var j=0,l=json.length;j<l;j++){
                        for(var key in json[j]){
                            this.$set(indata, key, json[j][key]);
                        }
                    }
                    plist[i].inventory=JSON.stringify(indata);
                    plist[i].secinventory = jsonval;

                }
                this.$refs["formData1"].validate((valid) => {});
                this.$refs["formData4"].validate((valid) => {
                    if(valid){
                        this.$refs["formData4"].clearValidate();
                    }
                });
                
                //商品资质认证
                //零售价
                this.formData.commodityprice = plist[0].commodityoldprice;
                //代理价
                this.formData.commodityoldprice =plist[0].primaryagentprice;
                this.$refs.ruleForm.validate(valid => {
                    if (valid) {
                        /*添加商品*/
                        this.formdisabled=true
                        this.formLoading=true
                        if(this.formData.commoditypiclist&&this.formData.commoditypiclist.length!==0){
                            this.formData.commodityicon=this.formData.commoditypiclist[0];
                            this.formData.piclist = this.formData.commoditypiclist.join(",");
                        }
                        var inventorylistobj=[];
                        if(plist){
                            let num=0;
                            for (let i=0;i< plist.length;i++) {
                                let nm=1;
                                num+=(plist[i].inventorynum)*(nm);
                                inventorylistobj.push(plist[i].inventory);
                                var inventory=  plist[i].inventory.substring(1,plist[i].inventory.length-1);
                                var inventorylist=inventory.split(":");
                                if(inventorylist[1].length<3){
                                    this.$message.warning("请完善商品规格信息！");
                                    this.formdisabled=false;
                                    this.formLoading =false;
                                    return false;
                                }
                                if(plist[i].costprice<1){
                                    this.$message.warning("请完善商品规格信息！");
                                     this.formdisabled=false;
                                    this.formLoading =false;
                                    return false;
                                }
                                if(plist[i].commodityprice <1){
                                    this.$message.warning("请完善商品规格信息！");
                                     this.formdisabled=false;
                                    this.formLoading =false;
                                    return false;
                                }

                                if(plist[i].commodityoldprice <1){
                                    this.$message.warning("请完善商品规格信息！");
                                     this.formdisabled=false;
                                    this.formLoading =false;
                                    return false;
                                }
                                if(plist[i].secondaryagentprice <1){
                                    this.$message.warning("请完善商品规格信息！");
                                     this.formdisabled=false;
                                    this.formLoading =false;
                                    return false;
                                }
                                if(plist[i].primaryagentprice <1){
                                    this.$message.warning("请完善商品规格信息！");
                                     this.formdisabled=false;
                                    this.formLoading =false;
                                    return false;
                                }
                                if(plist[i].primaryagentprice <1){
                                    this.$message.warning("请完善商品规格信息！");
                                     this.formdisabled=false;
                                    this.formLoading =false;
                                    return false;
                                }
                                if(plist[i].profitproportion < 0.0001 || plist[i].profitproportion >99.9999 ){
                                    this.$message.warning("县域收益占比应设置1~100之间！");
                                     this.formdisabled=false;
                                    this.formLoading =false;
                                    return false;
                                }
                                if(plist[i].profitproportion == undefined ){
                                    this.$message.warning("县域收益占比应设置1~100之间！");
                                    this.formdisabled=false;
                                    this.formLoading =false;
                                    return false;
                                }
                            }

                            this.formData.commoditynum=num;
                        }
                        var inventoryojb= this.arrNumber(inventorylistobj);
                        // console.info(inventoryojb)
                        for (let i = 0; i < plist.length; i++) {
                            var inventorycount=  inventoryojb[plist[i].inventory]
                            // console.info(inventoryojb[plist[i].inventory])
                            if(inventorycount>1){
                                this.$message.warning("商品不可添加俩个及以上的相同规格！");
                                this.formdisabled=false;
                                this.formLoading =false;
                                return false;
                            }
                        }
                        this.formData.param=JSON.stringify(plist);
                        // alert(JSON.stringify(this.plist));
                        this.formData.inputdata=JSON.stringify(this.inputData);
                        let flag = false;
                        var msg ="";
                        if(this.categoryTemplate==null ||  this.categoryTemplate==undefined) {
                            this.$message.warning("无商品模板！");
                            this.formdisabled=false;
                            this.formLoading =false;
                            return false;
                        }
                        //无商品属性模板
                        if ( this.attributecontenct == null || this.attributecontenct == undefined ) {
                            this.$message.warning("无商品属性模板！");
                            this.formdisabled=false;
                            this.formLoading =false;
                            return false;
                        }
                        //赋值商品属性模板
                            this.formData.attributecontenct = JSON.stringify(this.attributecontenct);
                            this.formData.attributeextendcontenct = JSON.stringify(this.attributeextendcontenct);
                        //赋值商品模板
                            this.formData.certificationcontent = JSON.stringify( this.categoryTemplate );
                        if ( this.attributecontenct != null && this.attributecontenct != undefined) {
                            this.attributecontenct.forEach((item) => {
                                if ( (item.fieldvalue == null || item.fieldvalue == "") && item.ismust == 0) {
                                    msg = item.fieldname;
                                    flag = true;
                                }
                            });
                        } else {
                            this.$message.warning("无商品属性模板！");
                            this.formdisabled=false;
                            this.formLoading =false;
                            return false;
                        }
                        if (flag) {
                            this.$message({
                            message: msg + "不能为空！",
                            type: "warning",
                            });
                            this.formdisabled=false;
                            this.formLoading =false;
                            return false;
                        };
                        if ( this.attributeextendcontenct != null && this.attributeextendcontenct != undefined) {
                            this.attributeextendcontenct.forEach((item) => {
                                if ( (item.fieldvalue == null || item.fieldvalue == "") && item.ismust == 0) {
                                    msg = item.extendfieldname;
                                    flag = true;
                                }
                            });
                        } else {
                            this.$message.warning("无商品属性模板！");
                            this.formdisabled=false;
                            this.formLoading =false;
                            return false;
                        }
                        if (flag) {
                            this.$message({
                            message: msg + "不能为空！",
                            type: "warning",
                            });
                            this.formdisabled=false;
                            this.formLoading =false;
                            return false;
                        };
                        this.formData.certificationcontent = JSON.stringify(this.categoryTemplate);
                        if(this.categoryTemplate.templateItemFormList!=null&&this.categoryTemplate.templateItemFormList!=undefined){
                            this.categoryTemplate.templateItemFormList.forEach(item => {
                                    if((item.fieldvalue==null||item.fieldvalue=="")&& item.ismust==0){
                                        msg = item.fieldname;
                                        flag = true;
                                    }
                                }
                            );
                        }else{
                            this.$message.warning("无商品模板！");
                            this.formdisabled=false;
                            this.formLoading =false;
                            return false;
                        }
                        if(flag){
                            this.$message({
                                message: msg+"不能为空！",
                                type: "warning"
                            });
                            this.formdisabled=false;
                            this.formLoading =false;
                            return false;
                        }
                        var params = new URLSearchParams(this.formData);

                        this.dis=false;
                        addBusCommodity(params).then(response => {
                            this.formLoading = false;
                            if (response.code != 0) {
                                this.$message.error(response.message);
                                this.formdisabled=false;
                                this.formLoading =false;
                                return false;
                            }
                            this.$message.success("操作成功");
                            this.uploadData = [];//图片
                            this.vuploadData=[];//视频

                            this.formData = {};
                            // this.$refs.tinymce.setContent("");


                            this.formLoading = false;
                            this.formVisible = false;
                            this.formdisabled=false
                            this.dis=true;
                            // 加载表格数据
                            this.getList();
                            // 清空表单
                            this.$refs.ruleForm.resetFields();
                            this.$refs.ruleForm.clearValidate();
                            //取消
                            this.closeCategory();


                        }).catch(() => {
                            this.formLoading = false;
                            this.formVisible = false;
                            this.dis=true;
                        });

                    }
                    
                });
               
            },
            /*----------*/
            //列表
            handleAvatarSuccess(response, file) {
                this.isSelect = false;
                if (response.status === 1) {
                    const filePath = response.data;
                    // alert(this.curRowIndex+"--"+filePath);
                    this.parameterlist[this.curRowIndex].inventorypic = filePath;
                    return;
                }
                this.$message.error("上传文件报错");
            },
            // 图片上传
            AvatarUpload(file) {
                this.fileName = file.name ? file.name : "";
                return false;
            },
            //图片上传成功
            vhandleSuccess(response, file) {
                this.isSelect = false;
                if (response.status === 1) {
                    const filePath = response.data;//视频地址
                    // const vPath = response.content;//视频截图地址
                    this.formData.videopic=filePath;
                    // console.info(JSON.stringify(this.uploadData));
                    return;
                }

                this.$message.error("上传文件报错");
            },
            // 图片上传
            vhandleChange(file) {
                this.fileName = file.name ? file.name : "";
                return false;
            },
            //图片上传成功
            handleSuccess(response, file) {
                console.info(response)
                console.info(this.formData.commoditypiclist)
                this.isSelect = false;
                if (response.status === 1) {
                    const filePath = response.data;
                    this.formData.commoditypiclist.push(filePath);
                    console.info(JSON.stringify(this.uploadData));
                    return;
                }

                this.$message.error("上传文件报错");
            },
            // 图片上传
            handleChange(file) {
                this.fileName = file.name ? file.name : "";
                return false;
            },
            handlePicRemove(file,fileList) {
                console.info("file=" + file+"fileList:"+fileList)
                console.info("commoditypiclist"+JSON.stringify(this.formData.commoditypiclist))
                var url = "";
                url = file.url;

                for (var i = 0; i < this.formData.commoditypiclist.length; i++) {

                    if (url===this.formData.commoditypiclist[i]){

                        this.formData.commoditypiclist.splice(i, 1);

                        console.info("commoditypiclist9999999999"+JSON.stringify(this.formData.commoditypiclist))

                    }
                }
                for (var i = 0; i < this.uploadData.length; i++) {

                    if (url===this.uploadData[i].url){

                        this.uploadData.splice(i, 1);

                        console.info("commoditypiclist9999999999"+JSON.stringify(this.formData.commoditypiclist))

                    }
                }

                console.info(this.uploadData)
            },

            //添加参数
            addpara() {
                let param = {
                    inventoryid: "",//          bigint not null auto_increment,
                    commodityid: "",//          bigint,
                    inventory: "",//      规格参数      text,
                    secinventory:"",       //规格参数2
                    commodityprice: 0,//    分销价   decimal(20,2),
                    commodityoldprice: 0,//  零售价  decimal(20,2),
                    primaryagentprice: 0,//一级代理
                    secondaryagentprice: 0,//二级代理
                    costprice: 0,//成本价
                    inventorynum: 0,//      库存   int,
                    buyfromnum: 1,//      起购   int,
                    profitproportion:0,//县域百分比
                    inventorypic: "",//   规格图片      varchar(200),
                    companytype: 0,//      单位    smallint comment '0:瓶 1箱 2:套',
                    boxnum: "",//      每箱瓶数         int comment '每箱瓶数',
                    savparameterlist: [],
                    splist:[]
                };
                let p = {
                    key: "",
                    val: ""
                };

                param.savparameterlist.push(p);
                this.parameterlist.push(param);
                console.info("++" + this.parameterlist[0].savparameterlist.val);
            },
            //删除
            paraDel(index, row) {
                this.parameterlist.splice(index, 1)
            },
            //关闭分类
            closeCategory() {
                this.classification = false;
                this.formData.topcategoryid = "";
                this.formData.secondarycategoryid = "";
                this.formData.thirdcategoryid = "";

                this.categoryobj = {};
                this.ThirdCategoryobj = {};
                this.SecondaryCategoryobj = {};
                this.inputData = [];
                if(this.$refs.ruleForm){
                   this.$refs.ruleForm.resetFields(); 
                   this.$refs.ruleForm.clearValidate();
                }
            },
            //add分类
            chosebtn() {
                this.classification = true
            },
            //查看评论
            lookcomment(v) {
                this.$router.push({path: '/commodity/comment', query: {cid: v}})
                // alert(v)
            },
            //add 隐藏表单
            hideForm() {
                // 更改值
                this.formVisible = !this.formVisible;
                // 清空表单
                if(this.$refs.ruleForm){
                   this.$refs.ruleForm.resetFields(); 
                   this.$refs.ruleForm.clearValidate();
                }
                
                this.parameterlist=[]
                this.query.warehousename = "";

                return true;
            },
            //上架
            onshelfschange(row) {
                this.loading = true;
                console.log(row)
                var params = new URLSearchParams();
                params.append("commodityid", row.commodityid);
                params.append("onshelfstatus", row.onshelfstatus);
                updateBusCommodity(params)
                    .then(response => {
                        this.loading = false;
                        if (response.code) {
                            this.$message.error(response.message);
                            return false;
                        }
                        this.loading = false;
                        this.$message.success("更新成功");
                        // 刷新数据
                    })
                    .catch(() => {
                        this.loading = false;
                    });
            },
            //推荐
            recommendchange(row) {
                this.loading = true;
                var params = new URLSearchParams();
                params.append("commodityid", row.commodityid);
                params.append("recommendstatus", row.recommendstatus);
                updateBusCommodity(params)
                    .then(response => {
                        this.loading = false;
                        if (response.code) {
                            this.$message.error(response.message);
                            return false;
                        }
                        this.loading = false;
                        this.$message.success("更新成功");
                        // 刷新数据

                    })
                    .catch(() => {
                        this.loading = false;
                    });

            },
            // 添加显示表单
            handleForm() {
                this.categoryTemplate = [];
                this.attributecontenct=[];
                this.attributeextendcontenct=[];
                this.formVisible = true;
                this.formName = "add"
                this.inputData=[];
                this.parameterlist=[];
                this.uploadData=[];
                this.categoryTemplateShow = false;
                this.formData={
                    attributecontenct: "",//商品基本属性
                    attributeextendcontenct: "",//扩展属性
                    commodityid: "",//商品id
                    commodityname: "",//商品名称
                    recommendstatus: 0,//商品'0不推荐1推荐',
                    onshelfstatus: 1,//商品 0全部，  1不上架 2上架',
                    commodityicon: "",//商品图片
                    commodityprice: "",// 售价    decimal(20,2),
                    commodityoldprice: "",//商品原价    decimal(20,2),
                    commodityfrom: "",// 货源地
                    topcategoryname: "",//一级分类
                    secondarycategoryname: "",//二级分类
                    thirdcategoryname: "",//三级分类
                    primaryentitybillie:"",
                    seniorentitybillie:"",
                    commoditytype:"",
                    commoditynum: "",// 库存
                    createtime: "",// 添加时间
                    commoditydesc: "",//商品描述
                    commoditypiclist: [],//图片
                    piclist: "", //图片列表
                    videopic:"" , //视频地址
                    /**/
                    topcategoryid: "",//一级分类id',
                    secondarycategoryid: "",//二级分类id',
                    thirdcategoryid: "",// 三级分类id,
                    inids: "" ,//参数id
                    param:"",
                    inputdata:""//全部参数
                }
                if(this.$refs.ruleForm){
                    this.$refs.ruleForm.clearValidate();
                    this.$refs.ruleForm.resetFields();
                }
            },
            //显示 查看弹框
            detailForm(index, row) {
                this.detailVisible = true;
                this.attributecontenct=[];
                this.attributeextendcontenct =[];
                if (row !== null) {

                    this.inputData=[]
                    this.formData = Object.assign({}, row);
                    this.formData.secondarycategoryid=row.secondarycategoryid;
                    this.formData.thirdcategoryid=row.thirdcategoryid;
                    //处理商品属性模板
                    if (row.attributecontenct != null) {
                        this.attributecontenct = JSON.parse(row.attributecontenct);
                        this.formData.attributecontenct = JSON.parse( row.attributecontenct );
                        if ( this.attributecontenct != null && this.attributecontenct != undefined) {
                                this.attributecontenct .forEach((item) => {
                                    this.formData1[item.fieldname] = item.fieldvalue;
                                });
                        }
                    }
                    if (row.attributeextendcontenct != null) {
                        this.attributeextendcontenct = JSON.parse(row.attributeextendcontenct);
                        this.formData.attributeextendcontenct = JSON.parse(row.attributeextendcontenct);
                        if ( this.attributeextendcontenct != null && this.attributeextendcontenct != undefined) {
                                this.attributeextendcontenct.forEach((item) => {
                                    this.formData1[item.extendfieldname] = item.fieldvalue;
                                });
                        }
                    }
                    if(row.certificationcontent!=null){
                        this.categoryTemplate = JSON.parse(row.certificationcontent);
                        this.formData.certificationcontent = JSON.parse(row.certificationcontent);
                        if(this.categoryTemplate.templateItemFormList!=null&&this.categoryTemplate.templateItemFormList!=undefined){
                            this.categoryTemplate.templateItemFormList.forEach(item => {
                                    // item.fieldvalue = this.formData4[item.fieldname];
                                    this.formData4[item.fieldname] = item.fieldvalue;
                                }
                            );
                        } else {
                                this.categoryTemplateShow = false;
                        }
                    }
                    if(row.inventorylist!=null&&row.inventorylist[0].inputdata!=null){
                        this.inputData=JSON.parse(row.inventorylist[0].inputdata);
                    }else{
                        let data={
                            key:"",
                            val:""
                        }
                        this.inputData.push(data);
                    }
                }
                let data=[];
                let pic=[];
                let vdata=[];
                let vpic=[];
                for (let i=0;i<row.commoditypiclist.length;i++){
                    let picdata=row.commoditypiclist[i];
                    if(picdata.recoursetype===0){
                        let obj={
                            name:"",
                            url:""
                        }
                        obj.name=i;
                        obj.url=picdata.picurl;
                        data.push(obj);
                        pic.push(picdata.picurl)
                    }
                    if(picdata.recoursetype===1){

                        let obj={
                            name:"",
                            url:""
                        }
                        obj.name=i;
                        obj.url=picdata.picurl;
                        vdata.push(obj);
                        vpic.push(picdata.picurl)
                    }
                }

                this.formData.videopic=vpic;
                this.vuploadData=vdata
                this.commoditypiclist=pic;
                this.formData.commoditypiclist=pic;
                this.uploadData=data;

                this.parameterlist=row.inventorylist;

                // console.log(row.inventorylist[0].commodityprice*100)
                for(let i=0;i<this.parameterlist.length;i++){
                    let sav=[];
                    this.$set(this.parameterlist[i], "savparameterlist", sav);
                    this.$set(this.parameterlist[i], "splist", sav);
                    console.log(this.parameterlist[i])
                    var a=this.parameterlist[i].inventory.indexOf("}");
                    var b=this.parameterlist[i].inventory.substring(1,a)
                    var a1=b.split(",");
                    var splist1=[];
                    for (let c=0;c<a1.length;c++) {
                        var s=a1[c].split(":")[1].substring(1,a1[c].split(":")[1].length-1);
                        splist1.push(s)
                    }
                     //县域百分比回显
                    if( this.parameterlist[i].profitproportion<1){
                        (this.parameterlist[i].profitproportion)*= 100;
                    }else{
                        (this.parameterlist[i].profitproportion)
                    }
                    this.parameterlist[i].splist=(splist1);
                    this.parameterlist[i].savparameterlist=JSON.parse(this.parameterlist[i].secinventory);

                    this.parameterlist[i].companytype= this.parameterlist[i].companytype.toString();
                }
                //参数
                let sav=[];
                if(this.parameterlist!=null&&this.parameterlist.length>0){

                    for(let i=0;i<this.parameterlist.length;i++){
                        let pdata=JSON.parse(this.parameterlist[i].secinventory);
                        for (let i=0;i<pdata.length;i++) {
                            let mdata=pdata[i]
                            for (let v in mdata){
                                let data={
                                    key:v,
                                    val:mdata[v].toString()
                                }
                                sav.push(mdata[v].toString());
                            }
                        }
                        this.parameterlist.savparameterlist=pdata;
                    }
                    this.parameterlist.splist=sav;
                }
                this.formName = "detail";
            },

            //显示 查看弹框
            inventoryForm(index, row) {
                console.log(row)
                this.inventoryVisible = true;
                if (row !== null) {
                    this.inputData=[]
                    this.formData = Object.assign({}, row);
                    this.formData.secondarycategoryid=row.secondarycategoryid;
                    this.formData.thirdcategoryid=row.thirdcategoryid;

                    if(row.certificationcontent!=null){
                        this.categoryTemplate = JSON.parse(row.certificationcontent);
                        this.formData.certificationcontent = JSON.parse(row.certificationcontent);
                        if(this.categoryTemplate.templateItemFormList!=null&&this.categoryTemplate.templateItemFormList!=undefined){
                            this.categoryTemplate.templateItemFormList.forEach(item => {
                                    // item.fieldvalue = this.formData4[item.fieldname];
                                    this.formData4[item.fieldname] = item.fieldvalue;
                                }
                            );
                        }
                    }
                    // this.formData.commoditytype=row.commoditytype+"";
                    if(row.inventorylist!=null && row.inventorylist[0].inputdata!=null){
                        this.inputData=JSON.parse(row.inventorylist[0].inputdata);
                    }else{
                        let data={
                            key:"",
                            val:""
                        }
                        this.inputData.push(data);
                    }
                }
                let data=[];
                let pic=[];
                let vdata=[];
                let vpic=[];
                for (let i=0;i<row.commoditypiclist.length;i++){
                    let picdata=row.commoditypiclist[i];
                    if(picdata.recoursetype===0){
                        let obj={
                            name:"",
                            url:""
                        }
                        obj.name=i;
                        obj.url=picdata.picurl;
                        data.push(obj);
                        pic.push(picdata.picurl)
                    }
                    if(picdata.recoursetype===1){

                        let obj={
                            name:"",
                            url:""
                        }
                        obj.name=i;
                        obj.url=picdata.picurl;
                        vdata.push(obj);
                        vpic.push(picdata.picurl)
                    }
                }

                this.formData.videopic=vpic;
                this.vuploadData=vdata
                this.commoditypiclist=pic;
                this.formData.commoditypiclist=pic;
                this.uploadData=data;

                this.parameterlist=row.inventorylist;
                for(let i=0;i<this.parameterlist.length;i++){
                    let sav=[];
                    this.$set(this.parameterlist[i], "savparameterlist", sav);
                    this.$set(this.parameterlist[i], "splist", sav);

                    var a=this.parameterlist[i].inventory.indexOf("}");
                    var b=this.parameterlist[i].inventory.substring(1,a)
                    var a1=b.split(",");
                    var splist1=[];
                    for (let c=0;c<a1.length;c++) {
                        var s=a1[c].split(":")[1].substring(1,a1[c].split(":")[1].length-1);
                        splist1.push(s)
                    }
                    this.parameterlist[i].splist=(splist1);
                    this.parameterlist[i].savparameterlist=JSON.parse(this.parameterlist[i].secinventory);
                    this.parameterlist[i].companytype= this.parameterlist[i].companytype.toString();
                }
                //参数
                let sav=[];
                if(this.parameterlist!=null&&this.parameterlist.length>0){
                    for(let i=0;i<this.parameterlist.length;i++){
                        let pdata=JSON.parse(this.parameterlist[i].secinventory);
                        for (let i=0;i<pdata.length;i++) {
                            let mdata=pdata[i]
                            for (let v in mdata){
                                let data={
                                    key:v,
                                    val:mdata[v].toString()
                                }
                                sav.push(mdata[v].toString());
                            }
                        }
                        this.parameterlist.savparameterlist=pdata;
                    }
                    this.parameterlist.splist=sav;
                }
                this.formName = "inventoryEdit";
            },
            // 隐藏详情弹框
            hideDetailForm() {
                // 更改值
                this.detailVisible = !this.detailVisible;
                // 清空表单
                this.formData={};
                if(this.$refs.ruleForm){
                   this.$refs.ruleForm.clearValidate() ;
                   this.$refs.ruleForm.resetFields() ;
                }
                return true;
            },
            //隐藏设置弹框
            hidemoney(formName) {
                // 更改值
                this.moneyVisible =!this.moneyVisible;
                this.$refs[formName].resetFields()
                this.$refs[formName].clearValidate()
            },
            //设置商品起购金额按钮
            setMoney(){
                this.getProfitBiliInfo()
                this.moneyVisible=true
            },
            //监听一下调整金额的值
			handleMoney(val){
				// console.log(val)
				let temp = val.toString();
				temp = temp.replace(/。/g, ".");
				temp = temp.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
				temp = temp.replace(/^\./g, ""); //验证第一个字符是数字
				temp = temp.replace(/\.{2,}/g, ""); //只保留第一个, 清除多余的
				temp = temp.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
				temp = temp.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3"); //只能输入两个小数
				this.money = temp;

			},
            //提交金额
            moneySubmit(formName){
                 this.$refs[formName].validate((valid) => {
					if (valid) {
                        //调接口
                        upProfitBili(this.funds)
                        .then(response => {
                            if (response.code != 0) {
                                this.$message.error(response.message);
                                return false;
                            }
                            this.moneyVisible = false;
                            this.$message.success("起购金额修改成功")
                            setTimeout(()=>{
                               this.$refs[formName].resetFields();
                               this.$refs[formName].clearValidate();
                            },300)
                        }).catch(() => {
                            this.$message.error("请求超时")
                        })
						
					} else {
						// console.log("error submit!!");
						return false;
					}
				});
            },
            getProfitBiliInfo(){
                getProfitBiliInfo()
                        .then(response => {
                            if (response.code != 0) {
                                this.$message.error(response.message);
                                return false;
                            }
                            this.funds.buyfromquota=this.getFloatNumber(response.data.buyfromquota)
                            this.funds.id=response.data.id
                        }).catch(() => {
                            this.$message.error("请求超时")
                        })
            },
            getFloatNumber(num) {
                    num += '';
                    num = num.replace(/[^0-9|\.]/g, '');
                    if (/^0+/) num = num.replace(/^0+/, '');
                    if (!/\./.test(num)) num += '.00';
                    if (/^\./.test(num)) num = '0' + num;
                    num += '00';
                    num = num.match(/\d+\.\d{2}/)[0];
                    return num;
            },
            hideclassification() {
                this.classification = !this.classification;
                return true;
            },

            //编辑
            editForm(index, row) {

                this.categoryTemplateShow = true;
                this.formData = Object.assign({}, formJson);
                if (row !== null) {
                    console.log(row)
                    this.inputData=[]
                    this.formData = Object.assign({}, row);
                    this.formData.secondarycategoryid=row.secondarycategoryid;
                    this.formData.thirdcategoryid=row.thirdcategoryid;
                    //商品属性模板处理
                    if (row.attributecontenct != null) {
                        let ss = Object.assign({}, row);
                        this.attributecontenct = JSON.parse(ss.attributecontenct);
                        this.formData.attributecontenct = JSON.parse(
                        row.attributecontenct
                        );
                        if (
                        this.attributecontenct != null &&
                        this.attributecontenct != undefined
                        ) {
                        this.attributecontenct.forEach((item) => {
                            this.formData1[item.fieldname] = item.fieldvalue;
                        });
                        } else {
                        this.categoryTemplateShow = false;
                        }
                    } else {
                        this.attributecontenct= this.emptyTemplate;
                    }
                    //扩展属性模板
                    if (row.attributeextendcontenct != null) {
                        let ss = Object.assign({}, row);
                        this.attributeextendcontenct = JSON.parse(ss.attributeextendcontenct);
                        this.formData.attributeextendcontenct = JSON.parse(
                        row.attributeextendcontenct
                        );
                        if (
                        this.attributeextendcontenct != null &&
                        this.attributeextendcontenct != undefined
                        ) {
                        this.attributeextendcontenct.forEach((item) => {
                            this.formData1[item.extendfieldname] = item.fieldvalue;
                        });
                        } else {
                        this.categoryTemplateShow = false;
                        }
                    } else {
                        this.attributeextendcontenct= this.emptyTemplate;
                    }

                    if(row.certificationcontent!=null){
                        this.categoryTemplate = JSON.parse(row.certificationcontent);
                        this.formData.certificationcontent = JSON.parse(row.certificationcontent);
                        if(this.categoryTemplate.templateItemFormList!=null&&this.categoryTemplate.templateItemFormList!=undefined){
                            this.categoryTemplate.templateItemFormList.forEach(item => {
                                    // item.fieldvalue = this.formData4[item.fieldname];
                                    this.formData4[item.fieldname] = item.fieldvalue;
                                }
                            );
                        }
                    }
                    if(row.inventorylist!=null&& row.inventorylist.length>0&&row.inventorylist[0].inputdata!=null){
                        this.inputData=JSON.parse(row.inventorylist[0].inputdata);
                    }else{
                        let data={
                            key:"",
                            val:""
                        }
                        this.inputData.push(data);
                    }
                }
                let data=[];
                let pic=[];
                let vdata=[];
                let vpic=[];
                for (let i=0;i<row.commoditypiclist.length;i++){
                    let picdata=row.commoditypiclist[i];
                    if(picdata.recoursetype===0){
                        let obj={
                            name:"",
                            url:""
                        }
                        obj.name=i;
                        obj.url=picdata.picurl;
                        data.push(obj);
                        pic.push(picdata.picurl)
                    }
                    if(picdata.recoursetype===1){

                        let obj={
                            name:"",
                            url:""
                        }
                        obj.name=i;
                        obj.url=picdata.picurl;
                        vdata.push(obj);
                        vpic.push(picdata.picurl)
                    }
                }

                this.formData.videopic=vpic;
                this.vuploadData=vdata
                this.commoditypiclist=pic;
                this.formData.commoditypiclist=pic;
                this.uploadData=data;

                this.parameterlist=row.inventorylist;
                console.info("row.inventorylist",row.inventorylist)
                for(let i=0;i<this.parameterlist.length;i++){
                    let sav=[];
                    this.$set(this.parameterlist[i], "savparameterlist", sav);
                    this.$set(this.parameterlist[i], "splist", sav);

                    var a=this.parameterlist[i].inventory.indexOf("}");
                    var b=this.parameterlist[i].inventory.substring(1,a)
                    var a1=b.split(",");
                    var splist1=[];
                    for (let c=0;c<a1.length;c++) {
                        var s=a1[c].split(":")[1].substring(1,a1[c].split(":")[1].length-1);
                        splist1.push(s)
                    }
                    //县域百分比回显

                    if( this.parameterlist[i].profitproportion<1){

                        (this.parameterlist[i].profitproportion)*= 100;

                    }else{
                        (this.parameterlist[i].profitproportion)
                    }

                    this.parameterlist[i].splist=(splist1);
                    this.parameterlist[i].savparameterlist=JSON.parse(this.parameterlist[i].secinventory);

                    this.parameterlist[i].companytype= this.parameterlist[i].companytype.toString();
                }
                //参数
                let sav=[];
                if(this.parameterlist!=null&&this.parameterlist.length>0){

                    for(let i=0;i<this.parameterlist.length;i++){
                        let pdata=JSON.parse(this.parameterlist[i].secinventory);

                        console.info(pdata)

                        for (let i=0;i<pdata.length;i++) {
                            let mdata=pdata[i]
                            for (let v in mdata){
                                let data={
                                    key:v,
                                    val:mdata[v].toString()
                                }
                                sav.push(mdata[v].toString());
                            }
                        }
                        this.parameterlist.savparameterlist=pdata;
                    }
                    this.parameterlist.splist=sav;
                }
                this.topchange1();
                this.formData.secondarycategoryid=row.secondarycategoryid;
                this.secondchange1();
                this.formData.thirdcategoryid=row.thirdcategoryid;
                this.formName = "edit";
                this.formVisible = true;

            },

            /*获取列表事件*/
            getList() {
                this.loading = true;
                this.list = [];
                getList(this.query).then(response => {
                    if (response.code != 0) {
                        this.$message.error(response.message);
                        return false;
                    }
                    this.list = response.data.list || []
                    // if (datalist.length > 0) {
                    //     let mylist = datalist
                    //     for (var i = 0; i < mylist.length; i++) {
                    //         if (mylist[i].onshelfstatus != null) {
                    //             mylist[i].onshelfstatus = mylist[i].onshelfstatus.toString();
                    //         }
                    //         if (mylist[i].recommendstatus != null) {
                    //             mylist[i].recommendstatus = mylist[i].recommendstatus.toString();
                    //         }
                    //         if(mylist[i].belongtype==0){//平台
                    //             mylist[i].companyName="平台"
                    //         }
                    //     }
                    //     console.log(mylist)
                    //     this.list = mylist

                    // }

                    this.totalNumber = response.data.totalNumber || 0;
                    setTimeout(() => {
                        this.loading = false;
                    }, 0.3 * 1000);
                }).catch(() => {
                    this.loading = false;
                    this.list = [];
                })
            },

            //一级
            topchange() {
                this.onSubmit();
                this.query.secondarycategoryid="";
                this.query.thirdcategoryid="";
                this.secondaryCategoryList=[];
                this.thirdCategoryList=[];
                let query={
                    parentid: this.query.topcategoryid,
                    level:2
                };
                getCategory(query)
                    .then(response => {
                        if (response.code) {
                            this.$message.error(response.message);
                        }
                        this.secondaryCategoryList = response.data || [];
                    })
                    .catch(() => {
                        this.secondaryCategoryList = [];
                    });
            },
            //二级
            secondchange() {
                this.onSubmit();
                this.query.thirdcategoryid="";
                this.thirdCategoryList=[]
                let query={
                    parentid: this.query.secondarycategoryid,
                    level:3
                };
                console.info(query)
                getCategory(query)
                    .then(response => {
                        if (response.code) {
                            this.$message.error(response.message);
                        }
                        this.thirdCategoryList = response.data || [];
                    })
                    .catch(() => {
                        this.thirdCategoryList = [];
                    });
            },

            //add一级
            topchange1() {
                this.formData.secondarycategoryid="";
                this.formData.thirdcategoryid="";
                this.secondaryCategoryList=[];
                this.thirdCategoryList=[]
                let query={
                    parentid: this.formData.topcategoryid,
                    level:2
                };

                if(this.formData.topcategoryid){
                    getCategory(query)
                        .then(response => {
                            if (response.code) {
                                this.$message.error(response.message);
                            }
                            let data = response.data || [];
                            this.secondaryCategoryList = data;
                            setTimeout(() => {
                                this.loading = false;
                            }, 0.3 * 1000);
                        })
                        .catch(() => {
                            this.loading = false;
                            this.list = [];
                            this.totalNumber = 0;
                        });
                }
            },
            //add二级
            secondchange1() {
                this.formData.thirdcategoryid="";
                this.thirdCategoryList=[]
                let query={
                    parentid: this.formData.secondarycategoryid,
                    level:3
                };
                if(this.formData.secondarycategoryid){
                    getCategory(query)
                        .then(response => {
                            if (response.code) {
                                this.$message.error(response.message);
                            }
                            let data = response.data || [];
                            this.thirdCategoryList = data;
                        })
                        .catch(() => {
                            this.thirdCategoryList = [];
                        });
                }
            },
            thirdchange1() {
                for (var i = 0; i < this.thirdCategoryList.length; i++) {
                    if (this.thirdCategoryList[i].topcategoryid == this.formData.thirdcategoryid) {
                        this.ThirdCategoryobj = this.thirdCategoryList[i];
                        if(this.ThirdCategoryobj.specification!=null){
                            let data = this.ThirdCategoryobj.specification.split(",");
                            let indata=[];
                            for (let i = 0; i < data.length; i++) {
                                let mydata = {
                                    key:"",
                                    val:""
                                };
                                mydata.key = data[i];
                                mydata.val = "";
                                indata.push(mydata);
                            }
                            this.inputData=indata;
                        }

                        this.formData.thirdcategoryname = this.thirdCategoryList[i].topcategoryname
                        this.formData.thirdcategoryid = this.thirdCategoryList[i].topcategoryid
                        this.classification = false;
                        break;
                    }
                }
                if(this.formData.thirdcategoryid){
                    this.getTemplate(this.formData.thirdcategoryid);

                }

            },
            getTemplate(thirdcategoryid) {
                this.categoryTemplate = [];
                this.attributecontenct=[];
                this.attributeextendcontenct=[];
                const formData = new FormData();
                formData.append("threeCategoryId", thirdcategoryid);
                getGoodsCertificationInfo(formData)
                    .then(response => {
                        if (response.code) {
                            this.$message.error(response.message);
                        }
                        this.categoryTemplate = response.data;
                        this.attributecontenct =response.data.attributesTemplateItemList
                        this.formData.attributecontenct =response.data.attributesTemplateItemList
                        this.attributeextendcontenct =response.data.extendAttributesTemplateItemList
                        if(this.categoryTemplate!=null && this.categoryTemplate.templateItemFormList!=undefined){
                            this.categoryTemplate.templateItemFormList.forEach((item)=>{
                                this.$set(this.formData4, item.fieldname, null);
                                    if (item.ismust == 0) {
                                        if (item.fieldtype == "图片") {
                                        this.$set(this.form4Rules, item.fieldname, {
                                            required: true,
                                            message: `${item.fieldname}为必填项`,
                                            trigger: "change",
                                        });
                                        } else {
                                        this.$set(this.form4Rules, item.fieldname, {
                                            required: true,
                                            message: `${item.fieldname}为必填项`,
                                            trigger: "blur",
                                        });
                                        }
                                    }
                            });
                        };
                        if(this.attributecontenct !=null){
                            this.categoryTemplateShow = true;
                            this.attributecontenct.forEach((item) => {
                                this.$set(this.formData1, item.fieldname, null);
                                if (item.ismust == 0) {
                                    this.$set(this.form1Rules, item.fieldname, {
                                    required: true,
                                    message: `${item.fieldname}为必填项`,
                                    trigger: "blur",
                                    });
                                }
                            });
                        };
                        if(this.attributeextendcontenct !=null){
                            this.categoryTemplateShow = true;
                            this.attributeextendcontenct.forEach((item) => {
                                this.$set(this.formData1, item.extendfieldname, null);
                                if (item.ismust == 0) {
                                    this.$set(this.form1Rules, item.extendfieldname, {
                                    required: true,
                                    message: `${item.extendfieldname}为必填项`,
                                    trigger: "blur",
                                    });
                                }
                            });
                        };
                    })
                    .catch(err => {
                        this.$message.error(err);
                    });
            },
            //获得分类
            getCategory() {
                let query={
                    level:1
                }
                getCategory(query)
                    .then(response => {
                        if (response.code) {
                            this.$message.error(response.message);
                        }
                        let data = response.data || [];
                        this.category = data;
                    })
                    .catch(() => {
                        this.category = [];
                    });
            },
            /*新增或者编辑提交事件*/
            formSumbit() {
                var ids = this.multipleSelection.map(item => item.commodityid).join(); //获取所有选中行的id组成的字符串，以逗号分隔
                if (ids == "") {
                    this.$message({
                        message: "请先选择",
                        type: "warning"
                    });
                    return;
                }

                this.$emit("on-select", ids, ids);

            },
            /*日期选择事件*/
            dateChange(val) {
                if (val == null) {
                    this.query.starttime = "";
                    this.query.endtime = "";
                } else {
                    this.query.starttime = val[0];
                    this.query.endtime = val[1];
                    this.query.currentPage = 1;
                }
                this.getList();
            },
            /*列表查询条件事件*/
            onSubmit() {
                this.query.currentPage = 1;
                this.getList();
            },

            /*刷新*/
            onRest() {
                //刷新事件需要重置查询条件
                this.createTime = [];
                this.query = {
                    currentPage: 1,
                    pageSize: 10,
                };
                this.getList();
            },

            /*点击页数*/
            handleCurrentChange(val) {
                this.query.currentPage = val;
                this.getList();
            },

            /*选择每页条数【10,20,30,40,50】*/
            handleSizeChange(val) {
                this.query.pageSize = val;
                this.getList();
            },

            /*取消全选事件*/
            toggleSelection(rows) {
                if (rows) {
                    rows.forEach(row => {
                        this.$refs.multipleTable.toggleRowSelection(row);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection();
                }

            },

            /*列表复选框选择事件*/
            handleSelectionChange(val) {
                this.multipleSelection = val;
                if (val == "") {
                    this.cancelToggle = false;
                    return;
                }
                this.cancelToggle = true;
            },

            /*全选删除事件*/
            delGroup() {
                var ids = this.multipleSelection.map(item => item.commodityid).join(); //获取所有选中行的id组成的字符串，以逗号分隔
                if (ids == "") {
                    this.$message({
                        message: "请先选择",
                        type: "warning"
                    });
                    return;
                }
                this.handleDel(ids);
            },

            /*选中事件*/
            handleDel(ids) {
                console.info()
                if (ids) {
                    this.$confirm("确认要删除吗?", "提示", {
                        type: "warning"
                    })
                        .then(() => {
                            this.loading = true;
                            var params = new URLSearchParams();
                            params.append("ids", ids);
                            delBusCommodity(params)
                                .then(response => {
                                    this.loading = false;
                                    if (response.code) {
                                        this.$message.error(response.message);
                                        return false;
                                    }
                                    this.$message.success("删除成功");
                                    // 刷新数据
                                    //this.list.splice(index, 1);
                                    this.getList();
                                })
                                .catch(() => {
                                    this.loading = false;
                                });
                        })
                        .catch(() => {
                            this.$message.warning("已取消");
                        });
                }
            },
            //提交库存修改数据
            inventoryFormSubmit() {
                // console.log('---更新后的库存'+ JSON.stringify(this.parameterlist));
                //用户未改变库存值，不提交
                let plist = this.parameterlist;
                let paramsData=[];

                for (let i = 0; i < plist.length; i++) {
                    let inventoryObj={
                        inventoryId:"",
                        inventoryNum:"",
                        commodityId: '',
                        buyfromnum: '',
                    }
                    inventoryObj.inventoryId  = plist[i].inventoryid;
                    inventoryObj.inventoryNum = plist[i].inventorynum;
                    if(inventoryObj.inventoryNum>99999){
                       this.$message.warning("库存不可以大于99999")
                       return
                    }
                    inventoryObj.buyfromnum = plist[i].buyfromnum;
                    if(inventoryObj.buyfromnum>99999){
                       this.$message.warning("起购量不可以大于99999")
                       return
                    }
                     if (plist[i].inventorynum==null||plist[i].inventorynum=='') {
                        this.$message.warning("库存不能为空");
                        return false;
                    }
                    if (plist[i].inventorynum < 0 || plist[i].inventorynum=='') {
                        this.$message.warning("库存不能小于0");
                        return false;
                    }
                    if (plist[i].buyfromnum==null||plist[i].buyfromnum=='') {
                        this.$message.warning("起购不能为空");
                        return false;
                    }
                    if (plist[i].buyfromnum < 1 || plist[i].buyfromnum=='') {
                        this.$message.warning("起购不能小于1");
                        return false;
                    }
                    if(plist[i].buyfromnum>plist[i].inventorynum){
                        this.$message.warning("起购不能大于库存，请重新输入");
                        return false;
                    }
                    inventoryObj.commodityId = this.formData.commodityid
                    paramsData.push(inventoryObj);
                }
                var params = new URLSearchParams();
                params.append("paramsData", JSON.stringify(paramsData));
                // console.log('库存更新提交的数据：'+ JSON.stringify(paramsData));

                updateCommodityInventory(params).then((response) => {
                    this.formLoading = true;
                    if (response.code != 0) {
                        this.$message.error(response.message);
                        return false;
                    }
                    this.$message.success("操作成功");

                    this.formData = {};
                    this.formLoading = false;
                    this.inventoryVisible = false;
                    this.dis = true;
                    // 加载表格数据
                    this.getList();
                }).catch(() => {
                    this.formLoading = false;
                    this.inventoryVisible = false;
                    this.dis = true;
                });
            },
            openRejectDialog(row) {
                this.$alert(row.rejectreason, '拒绝原因', {
                    confirmButtonText: '确定'
                });
            },

        },

        created() {
            this.getList();
            this.getCategory();
            // this.getProfitBiliInfo()
        }
    }

</script>
<style type="text/css" scoped>
    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }

    .avatar-uploader-icon {
        font-size: 21px;
        color: #8c939d;
        width: 50px;
        height: 50px;
        line-height: 178px;
        text-align: center;
    }

    .avatar {
        width: 178px;
        height: 178px;
        display: block;}
    .thridTitle {
        margin-left: 60px !important;
        font-size: 16px;
        font-weight: 600;
    }
    .spanTitle{
        margin-left:5px !important ;
        font-size: 16px !important;
        font-weight: 500 !important;
    }

</style>




